﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.ComponentModel;

namespace Phone.Framework.Data
{
    public class DataBaseHelper
    {
        public static T CreateDataBase<T>(string DBConnectionString) where T:DbDataContext
        {
            
            // Create the database if it does not exist.
            DbDataContext db = (DbDataContext)
                Activator.CreateInstance(typeof(T), 
                string.Format("Data Source=isostore:{0}.sdf", DBConnectionString));
           
                if (db.DatabaseExists() == false)
                {
                    // Create the local database.
                    db.CreateDatabase();
                }
            return db as T;
        }

        public static T CreateEmptyDataBase<T>(string DBConnectionString) where T : DbDataContext
        {
            DbDataContext db = (DbDataContext)
                           Activator.CreateInstance(typeof(T),
                           string.Format("Data Source=isostore:{0}.sdf", DBConnectionString));

            if (db.DatabaseExists() == false)
            {
                db.CreateDatabase();
            }
            else
            {
                db.DeleteDatabase();
                // Create the local database.
                db.CreateDatabase();
            }
            return db as T;
        }
    }

    public partial class DbDataContext : DataContext
    {
     
        public DbDataContext(string connectionString)
            : base(connectionString)
        { }

    
    }
}